home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / xpcom / nsINIParser.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  6KB  |  159 lines

  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is Mozilla Communicator client code, released
  16.  * March 31, 1998.
  17.  *
  18.  * The Initial Developer of the Original Code is
  19.  * Netscape Communications Corporation.
  20.  * Portions created by the Initial Developer are Copyright (C) 1998
  21.  * the Initial Developer. All Rights Reserved.
  22.  *
  23.  * Contributor(s):
  24.  *   Samir Gehani <sgehani@netscape.com>
  25.  *   Benjamin Smedberg <bsmedberg@covad.net>
  26.  *
  27.  * Alternatively, the contents of this file may be used under the terms of
  28.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  29.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  30.  * in which case the provisions of the GPL or the LGPL are applicable instead
  31.  * of those above. If you wish to allow use of your version of this file only
  32.  * under the terms of either the GPL or the LGPL, and not to allow others to
  33.  * use your version of this file under the terms of the MPL, indicate your
  34.  * decision by deleting the provisions above and replace them with the notice
  35.  * and other provisions required by the GPL or the LGPL. If you do not delete
  36.  * the provisions above, a recipient may use your version of this file under
  37.  * the terms of any one of the MPL, the GPL or the LGPL.
  38.  *
  39.  * ***** END LICENSE BLOCK ***** */
  40.  
  41. // This file was shamelessly copied from mozilla/xpinstall/wizard/unix/src2
  42.  
  43. #ifndef nsINIParser_h__
  44. #define nsINIParser_h__
  45.  
  46. #include "nscore.h"
  47. #include "nsClassHashtable.h"
  48. #include "nsAutoPtr.h"
  49.  
  50. #include <stdio.h>
  51.  
  52. class nsILocalFile;
  53.  
  54. class NS_COM_GLUE nsINIParser
  55. {
  56. public:
  57.     nsINIParser() { }
  58.     ~nsINIParser() { }
  59.  
  60.     /**
  61.      * Initialize the INIParser with a nsILocalFile. If this method fails, no
  62.      * other methods should be called. This method reads and parses the file,
  63.      * the class does not hold a file handle open. An instance must only be
  64.      * initialized once.
  65.      */
  66.     nsresult Init(nsILocalFile* aFile);
  67.  
  68.     /**
  69.      * Initialize the INIParser with a file path. If this method fails, no
  70.      * other methods should be called. This method reads and parses the file,
  71.      * the class does not hold a file handle open. An instance must only
  72.      * be initialized once.
  73.      */
  74.     nsresult Init(const char *aPath);
  75.  
  76.     /**
  77.      * Callback for GetSections
  78.      * @return PR_FALSE to stop enumeration, or PR_TRUE to continue.
  79.      */
  80.     typedef PRBool
  81.     (* PR_CALLBACK INISectionCallback)(const char *aSection,
  82.                                        void *aClosure);
  83.  
  84.     /**
  85.      * Enumerate the sections within the INI file.
  86.      */
  87.     nsresult GetSections(INISectionCallback aCB, void *aClosure);
  88.  
  89.     /**
  90.      * Callback for GetStrings
  91.      * @return PR_FALSE to stop enumeration, or PR_TRUE to continue
  92.      */
  93.     typedef PRBool
  94.     (* PR_CALLBACK INIStringCallback)(const char *aString,
  95.                                       const char *aValue,
  96.                                       void *aClosure);
  97.  
  98.     /**
  99.      * Enumerate the strings within a section. If the section does
  100.      * not exist, this function will silently return.
  101.      */
  102.     nsresult GetStrings(const char *aSection,
  103.                         INIStringCallback aCB, void *aClosure);
  104.  
  105.     /**
  106.      * Get the value of the specified key in the specified section
  107.      * of the INI file represented by this instance.
  108.      *
  109.      * @param aSection      section name
  110.      * @param aKey          key name
  111.      * @param aResult       the value found
  112.      * @throws NS_ERROR_FAILURE if the specified section/key could not be
  113.      *                          found.
  114.      */
  115.     nsresult GetString(const char *aSection, const char *aKey, 
  116.                        nsACString &aResult);
  117.  
  118.     /**
  119.      * Alternate signature of GetString that uses a pre-allocated buffer
  120.      * instead of a nsACString (for use in the standalone glue before
  121.      * the glue is initialized).
  122.      *
  123.      * @throws NS_ERROR_LOSS_OF_SIGNIFICANT_DATA if the aResult buffer is not
  124.      *         large enough for the data. aResult will be filled with as
  125.      *         much data as possible.
  126.      *         
  127.      * @see GetString [1]
  128.      */
  129.     nsresult GetString(const char *aSection, const char* aKey,
  130.                        char *aResult, PRUint32 aResultLen);
  131.  
  132. private:
  133.     struct INIValue
  134.     {
  135.         INIValue(const char *aKey, const char *aValue)
  136.             : key(aKey), value(aValue) { }
  137.  
  138.         const char *key;
  139.         const char *value;
  140.         nsAutoPtr<INIValue> next;
  141.     };
  142.  
  143.     struct GSClosureStruct
  144.     {
  145.         INISectionCallback  usercb;
  146.         void               *userclosure;
  147.     };
  148.  
  149.     nsClassHashtable<nsDepCharHashKey, INIValue> mSections;
  150.     nsAutoArrayPtr<char> mFileContents;    
  151.  
  152.     nsresult InitFromFILE(FILE *fd);
  153.  
  154.     static PLDHashOperator GetSectionsCB(const char *aKey,
  155.                                          INIValue *aData, void *aClosure);
  156. };
  157.  
  158. #endif /* nsINIParser_h__ */
  159.